package com.zige.zige.dialog;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.zige.zige.R;
import com.zige.zige.utils.SharedPreferencesUtils;

/**
 * Created by Fei on 2015/12/15.
 */
public class EvaluationAppDialog extends DialogFragment {

    private View view;
    private TextView tv_go_evaluation,tv_ignore;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        view = inflater.inflate(R.layout.dialog_evaluation_app, container);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        SharedPreferencesUtils.saveValue(getActivity(),"showCommentAlert",false);
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        window.setAttributes(lp);
        getDialog().show();
        getDialog().setCanceledOnTouchOutside(false);
        getDialog().setCancelable(false);
        initView();
        setContext();
        return  view;

    }

    private void initView(){
        tv_go_evaluation = (TextView) view.findViewById(R.id.tv_go_evaluation);
        tv_go_evaluation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("market://details?id="+getActivity().getPackageName());
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                getDialog().dismiss();
            }
        });
    }

    public void setContext(){
        tv_ignore = (TextView)view.findViewById(R.id.tv_ignore);
        tv_ignore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDialog().dismiss();
            }
        });
    }
}
